package com.dict.classes;

import java.sql.ResultSet;
import java.util.Vector;

public class Users extends User{
	private int pos;
	public Vector UsersVec;

	public void load()  throws Exception 
	{		
		this.pos = -1;
		this.UsersVec = new Vector();
		UserDb db = new UserDb();		
		ResultSet rs = db.getAllUsersSet();
		
		while(rs.next())
		{ 
			User jObject = new User();
			jObject.setId(rs.getInt(1));
			jObject.setUsername(rs.getString(2));
			jObject.setPassword(rs.getString(3));
			this.UsersVec.add(jObject);
		}
		db.disconnect();
	}

	public int size()
	{
		if(this.isNull())
			return 0;
		else
			return this.UsersVec.size();
	}

	public boolean isNull()
	{
		if(this.UsersVec == null)
			return true;
		else
			return false;
	}

	public void add(User anObject)
	{
		if(this.isNull())
		{
			this.pos = -1;
			this.UsersVec = new Vector();
		}
		this.UsersVec.add(anObject);
	}
	
	public boolean next()
	{
		if(!(this.isNull())) 
		{
			pos++;
			return  (pos < this.UsersVec.size());
		} 
		else
		{
			return false;
		}
	}

	public User getNext() 
	{
		return (User) this.UsersVec.elementAt(this.pos);
	}
}
